import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:online_study/base/app_title.dart';
import 'package:online_study/mine/answer/answer_result.dart';
import 'package:online_study/mine/exam/exam_bean.dart';
import 'package:online_study/mine/exam/exam_item.dart';
import 'package:online_study/theme/colors.dart';
import 'package:online_study/theme/size.dart';

//每日答题
class AnswerDailyPage extends StatefulWidget {
  @override
  _AnswerDailyPageState createState() => _AnswerDailyPageState();
}

class _AnswerDailyPageState extends State<AnswerDailyPage> {
  List<ExamBean> _list = [];
  int _currentIndex = 0;

  @override
  void initState() {
    super.initState();
    [1, 2, 3, 4, 5, 6, 7, 8, 9].forEach((element) {
      var examBean = ExamBean();
      if (element > 4) {
        examBean.isMulti = true;
      } else {
        examBean.isMulti = false;
      }
      examBean.index = element;
      examBean.question = "提升自身形象的三大要素";
      List<String> result = ["A . 肢体语言", "B . 着装", "C . 专业技能", "D . 过度饮酒"];
      examBean.answers = result;
      _list.add(examBean);
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: ThemeColor.colorWhite,
      appBar: AppBar(
        leading: BackButton(color: ThemeColor.color333333),
        titleSpacing: 0,
        backgroundColor: ThemeColor.colorWhite,
        elevation: ThemeSize.appElevation,
        title: AppTitle("每日答题"),
      ),
      body: SingleChildScrollView(
        child: Column(
          children: [
            Container(
              color: ThemeColor.colorWhite,
              alignment: Alignment.centerLeft,
              height: ThemeSize.height36,
              padding: EdgeInsets.symmetric(horizontal: ThemeSize.width19),
              child: Row(
                children: [
                  Expanded(
                      child: Text("题目",
                          style: TextStyle(
                              color: ThemeColor.color333333,
                              fontSize: ThemeSize.sp13,
                              fontWeight: FontWeight.bold))),
                  Text(
                      (_currentIndex + 1).toString() +
                          "/" +
                          _list.length.toString(),
                      style: TextStyle(
                          color: ThemeColor.colorFA5151,
                          fontSize: ThemeSize.sp13))
                ],
              ),
            ),
            ExamItemPage(_list[_currentIndex]),
            Container(
              padding: EdgeInsets.symmetric(vertical: ThemeSize.height120),
              color: ThemeColor.colorWhite,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Offstage(
                    offstage: _currentIndex == 0,
                    child: GestureDetector(
                      child: Container(
                        margin:
                        EdgeInsets.symmetric(horizontal: ThemeSize.width10),
                        padding:
                        EdgeInsets.symmetric(horizontal: ThemeSize.width45),
                        alignment: Alignment.center,
                        height: ThemeSize.height36,
                        decoration: BoxDecoration(
                            color: ThemeColor.color1485EE,
                            borderRadius:
                            BorderRadius.circular(ThemeSize.height18)),
                        child: Text(
                          (_currentIndex == (_list.length - 1))
                              ? "完成答题"
                              : "上一题",
                          style: TextStyle(
                              color: ThemeColor.colorWhite,
                              fontSize: ThemeSize.sp16),
                        ),
                      ),
                      onTap: () {
                        if (_currentIndex == (_list.length - 1)) {
                          Get.back();
                          Get.to(() => AnswerResultPage());
                        } else {
                          _currentIndex--;
                          setState(() {});
                        }
                      },
                    ),
                  ),
                  Offstage(
                    offstage: _currentIndex == _list.length - 1,
                    child: GestureDetector(
                      child: Container(
                        margin:
                        EdgeInsets.symmetric(horizontal: ThemeSize.width10),
                        padding:
                        EdgeInsets.symmetric(horizontal: ThemeSize.width45),
                        alignment: Alignment.center,
                        height: ThemeSize.height36,
                        decoration: BoxDecoration(
                            color: ThemeColor.color1485EE,
                            borderRadius:
                            BorderRadius.circular(ThemeSize.height18)),
                        child: Text(
                          "下一题",
                          style: TextStyle(
                              color: ThemeColor.colorWhite,
                              fontSize: ThemeSize.sp16),
                        ),
                      ),
                      onTap: () {
                        _currentIndex++;
                        setState(() {});
                      },
                    ),
                  ),
                ],
              ),
            )
          ],
        ),
      ),
    );
  }
}
